import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/index'),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'profile',
        component: () => import('@/views/system/user/profile/index'),
        name: 'Profile',
        meta: { title: '个人中心', icon: 'user' }
      }
    ]
  }
]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
  {
    path: '/system/user-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:user:edit'],
    children: [
      {
        path: 'role/:userId(\\d+)',
        component: () => import('@/views/system/user/authRole'),
        name: 'AuthRole',
        meta: { title: '分配角色', activeMenu: '/system/user' }
      }
    ]
  },
  {
    path: '/system/role-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:role:edit'],
    children: [
      {
        path: 'user/:roleId(\\d+)',
        component: () => import('@/views/system/role/authUser'),
        name: 'AuthUser',
        meta: { title: '分配用户', activeMenu: '/system/role' }
      }
    ]
  },
  {
    path: '/system/dict-data',
    component: Layout,
    hidden: true,
    permissions: ['system:dict:list'],
    children: [
      {
        path: 'index/:dictId(\\d+)',
        component: () => import('@/views/system/dict/data'),
        name: 'Data',
        meta: { title: '字典数据', activeMenu: '/system/dict' }
      }
    ]
  },
  {
    path: '/system/oss-config',
    component: Layout,
    hidden: true,
    permissions: ['system:oss:list'],
    children: [
      {
        path: 'index',
        component: () => import('@/views/system/oss/config'),
        name: 'OssConfig',
        meta: { title: '配置管理', activeMenu: '/system/oss' }
      }
    ]
  },
  {
    path: '/tool/gen-edit',
    component: Layout,
    hidden: true,
    permissions: ['tool:gen:edit'],
    children: [
      {
        path: 'index/:tableId(\\d+)',
        component: () => import('@/views/tool/gen/editTable'),
        name: 'GenEdit',
        meta: { title: '修改生成配置', activeMenu: '/tool/gen' }
      }
    ]
  },
  {
    path: '/oms/warehouseInfo',
    component: Layout,
    hidden: true,
    permissions: ['oms:task:add','oms:task:edit','oms:task:pack'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/oms/warehouse/edit'),
        name: 'warehouseAdd',
        meta: { title: '入库申请新增', activeMenu: '/oms/warehouse' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/oms/warehouse/edit'),
        name: 'warehouseEdit',
        meta: { title: '入库申请编辑', activeMenu: '/oms/warehouse' }
      }
    ]
  },
  {
    path: '/oms/exWarehouseInfo',
    component: Layout,
    hidden: true,
    permissions: ['oms:task:add','oms:task:edit','oms:task:pack'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/oms/exWarehouse/edit'),
        name: 'exWarehouseAdd',
        meta: { title: '出库申请新增', activeMenu: '/oms/exWarehouse' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/oms/exWarehouse/edit'),
        name: 'exWarehouseEdit',
        meta: { title: '出库申请编辑', activeMenu: '/oms/exWarehouse' }
      }
    ]
  },
  {
    path: '/oms/transferInfo',
    component: Layout,
    hidden: true,
    permissions: ['oms:task:add','oms:task:edit','oms:task:pack'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/oms/transfer/edit'),
        name: 'transferAdd',
        meta: { title: '调用申请新增', activeMenu: '/oms/transfer' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/oms/transfer/edit'),
        name: 'transferEdit',
        meta: { title: '调用申请编辑', activeMenu: '/oms/transfer' }
      }
    ]
  },
  {
    path: '/oms/dealInfo',
    component: Layout,
    hidden: true,
    permissions: ['oms:task:add','oms:task:edit'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/oms/deal/edit'),
        name: 'dealAdd',
        meta: { title: '处置申请新增', activeMenu: '/oms/deal' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/oms/deal/edit'),
        name: 'dealEdit',
        meta: { title: '处置申请编辑', activeMenu: '/oms/deal' }
      },
      {
        path: 'addDeal',
        component: () => import('@/views/oms/deal/edit'),
        name: 'dealAdd',
        meta: { title: '处置申请新增', activeMenu: '/oms/deal' }
      }
    ]
  },
  {
    path: '/wms/warehouseInfo',
    component: Layout,
    hidden: true,
    permissions: ['wms:warehouse:add','wms:warehouse:edit','wms:warehouse:pack','wms:warehouse:list'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/wms/warehouse/edit'),
        name: 'warehouseAdd',
        meta: { title: '入库单新增', activeMenu: '/wms/warehouse' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/wms/warehouse/edit'),
        name: 'warehouseEdit',
        meta: { title: '入库单编辑', activeMenu: '/wms/warehouse' }
      },
      {
        path: 'putTask/:wid',
        component: () => import('@/views/wms/warehouse/putTask'),
        name: 'putTaskEdit',
        meta: { title: '上架任务', activeMenu: '/wms/warehouse' }
      }
    ]
  },
  {
    path: '/wms/putTaskInfo',
    component: Layout,
    hidden: true,
    permissions: ['wms:putTask:add','wms:putTask:edit'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/wms/putTask/edit'),
        name: 'putTaskAdd',
        meta: { title: '上架任务新增', activeMenu: '/wms/putTask' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/wms/putTask/edit'),
        name: 'putTaskEdit',
        meta: { title: '上架任务编辑', activeMenu: '/wms/putTask' }
      },
      {
        path: 'info/:id',
        component: () => import('@/views/wms/putTask/info'),
        name: 'putTaskEdit',
        meta: { title: '上架任务查看', activeMenu: '/wms/putTask' }
      }
    ]
  },
  {
    path: '/wms/exWarehouseInfo',
    component: Layout,
    hidden: true,
    permissions: ['wms:exWarehouse:add','wms:exWarehouse:edit'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/wms/exWarehouse/edit'),
        name: 'exWarehouseAdd',
        meta: { title: '出库单新增', activeMenu: 'exWarehouse' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/wms/exWarehouse/edit'),
        name: 'exWarehouseEdit',
        meta: { title: '出库单编辑', activeMenu: '/wms/exWarehouse' }
      },
      {
        path: 'pick/:wid',
        component: () => import('@/views/wms/exWarehouse/pick'),
        name: 'exWarehouseEdit',
        meta: { title: '挑拣任务新增', activeMenu: '/wms/exWarehouse' }
      }
    ]
  },
  {
    path: '/wms/pickInfo',
    component: Layout,
    hidden: true,
    permissions: ['wms:pick:add','wms:pick:edit'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/wms/pick/edit'),
        name: 'pickAdd',
        meta: { title: '挑拣任务新增', activeMenu: '/wms/pick' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/wms/pick/edit'),
        name: 'pickEdit',
        meta: { title: '挑拣任务编辑', activeMenu: '/wms/pick' }
      },
      {
        path: 'info/:id',
        component: () => import('@/views/wms/pick/info'),
        name: 'putTaskEdit',
        meta: { title: '挑拣任务查看', activeMenu: '/wms/pick' }
      }
    ]
  },
  {
    path: '/wms/transferInfo',
    component: Layout,
    hidden: true,
    permissions: ['wms:exWarehouse:add','wms:exWarehouse:edit'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/wms/transfer/edit'),
        name: 'transferAdd',
        meta: { title: '调用单新增', activeMenu: 'transfer' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/wms/transfer/edit'),
        name: 'transferEdit',
        meta: { title: '调用单编辑', activeMenu: '/wms/transfer' }
      },
      {
        path: 'pick/:wid',
        component: () => import('@/views/wms/transfer/pick'),
        name: 'transferEdit',
        meta: { title: '挑拣任务新增', activeMenu: '/wms/transfer' }
      }
    ]
  },
  {
    path: '/wms/dealInfo',
    component: Layout,
    hidden: true,
    permissions: ['wms:deal:add','wms:deal:edit'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/wms/deal/edit'),
        name: 'dealAdd',
        meta: { title: '处置单新增', activeMenu: 'deal' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/wms/deal/edit'),
        name: 'dealEdit',
        meta: { title: '处置单编辑', activeMenu: '/wms/deal' }
      },
      {
        path: 'pick/:dealId',
        component: () => import('@/views/wms/deal/pick'),
        name: 'dealEdit',
        meta: { title: '挑拣任务新增', activeMenu: '/wms/deal' }
      }
    ]
  },
  {
    path: '/wms/store',
    component: Layout,
    hidden: true,
    permissions: ['wms:store:add'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/wms/store/edit'),
        name: 'storeAdd',
        meta: { title: '仓库信息新增', activeMenu: '/wms/wmsstore/store' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/wms/store/edit'),
        name: 'storeEdit',
        meta: { title: '仓库信息编辑', activeMenu: '/wms/wmsstore/store' }
      },
      {
        path: 'cabinet',
        component: () => import('@/views/wms/cabinet/index'),
        name: 'cabinetGroup',
        meta: { title: '货柜管理', activeMenu: 'wms/wmsstore/cabinetGroup' }
      }
    ]
  },
  {
    path: '/wms/storeAreas',
    component: Layout,
    hidden: true,
    permissions: ['wms:storeArea:list'],
    children: [
      {
        path: 'list',
        component: () => import('@/views/wms/storeArea/index'),
        name: 'cabinetGroup',
        meta: { title: '库区列表', activeMenu: '/wms/wmsstore/store' }
      }
    ]
  },
  {
    path: '/wms/storeCabinet',
    component: Layout,
    hidden: true,
    permissions: ['wms:cabinet:add'],
    children: [
      {
        path: 'cabinet',
        component: () => import('@/views/wms/cabinet/index'),
        name: 'cabinetGroup',
        meta: { title: '柜列管理', activeMenu: 'wms/wmsstore/cabinetGroup' }
      }
    ]
  },
  {
    path: '/wms/storeLocator',
    component: Layout,
    hidden: true,
    permissions: ['wms:locator:add'],
    children: [
      {
        path: 'list',
        component: () => import('@/views/wms/locator/index'),
        name: 'cabinetGroup',
        meta: { title: '库位管理', activeMenu: 'wms/wmsstore/cabinetGroup' }
      },
      {
        path: 'car',
        component: () => import('@/views/wms/locator/car'),
        name: 'cabinetGroupCar',
        meta: { title: '车位管理', activeMenu: 'wms/wmsstore/cabinetGroupCar' }
      }
    ]
  },
  {
    path: '/wms/inventories',
    component: Layout,
    hidden: true,
    permissions: ['wms:inventory:list'],
    children: [
      {
        path: 'list',
        component: () => import('@/views/wms/inventory/index'),
        name: 'cabinetGroup',
        meta: { title: '库存情况', activeMenu: 'wms/wmsstore/cabinetGroup' }
      }
    ]
  },
  {
    path: '/tms/carInfo',
    component: Layout,
    hidden: true,
    permissions: ['tms:car:add','tms:car:edit'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/tms/car/edit'),
        name: 'carAdd',
        meta: { title: '车辆信息新增', activeMenu: '/tms/car' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/tms/car/edit'),
        name: 'carEdit',
        meta: { title: '车辆信息编辑', activeMenu: '/tms/car' }
      }
    ]
  },
  {
    path: '/tms/addressInfo',
    component: Layout,
    hidden: true,
    permissions: ['tms:address:add','tms:address:edit'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/tms/address/edit'),
        name: 'addressAdd',
        meta: { title: '地址信息新增', activeMenu: '/tms/address' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/tms/address/edit'),
        name: 'addressEdit',
        meta: { title: '地址信息编辑', activeMenu: '/tms/address' }
      }
    ]
  },
  {
    path: '/tms/linesInfo',
    component: Layout,
    hidden: true,
    permissions: ['tms:lines:add','tms:lines:edit'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/tms/lines/edit'),
        name: 'linesAdd',
        meta: { title: '线路信息新增', activeMenu: '/tms/lines' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/tms/lines/edit'),
        name: 'linesEdit',
        meta: { title: '线路信息编辑', activeMenu: '/tms/lines' }
      }
    ]
  },
  {
    path: '/tms/scheduleInfo',
    component: Layout,
    hidden: true,
    permissions: ['tms:schedule:add','tms:schedule:edit'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/tms/schedule/edit'),
        name: 'scheduleAdd',
        meta: { title: '车次信息新增', activeMenu: '/tms/schedule' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/tms/schedule/edit'),
        name: 'scheduleEdit',
        meta: { title: '车次信息编辑', activeMenu: '/tms/schedule' }
      }
    ]
  },
  {
    path: '/tms/orderInfo',
    component: Layout,
    hidden: true,
    permissions: ['tms:order:add','tms:order:edit','tms:order:query'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/tms/order/edit'),
        name: 'orderEdit',
        meta: { title: '订单信息新增', activeMenu: '/tms/order' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/tms/order/edit'),
        name: 'orderEdit',
        meta: { title: '订单信息编辑', activeMenu: '/tms/order' }
      },
      {
        path: 'detail/:id',
        component: () => import('@/views/tms/order/info'),
        name: 'orderEdit',
        meta: { title: '订单信息查看', activeMenu: '/tms/order' }
      },
      {
        path: 'initBean/:ids',
        component: () => import('@/views/tms/order/staging'),
        name: 'orderStaging',
        meta: { title: '暂存派车', activeMenu: '/tms/order' }
      },
    ]
  },
  {
    path: '/tms/waybillInfo',
    component: Layout,
    hidden: true,
    permissions: ['tms:waybill:add','tms:waybill:edit','tms:waybill:query'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/tms/waybill/edit'),
        name: 'waybillEdit',
        meta: { title: '运单信息新增', activeMenu: '/tms/waybill' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/tms/waybill/edit'),
        name: 'waybillEdit',
        meta: { title: '运单信息编辑', activeMenu: '/tms/waybill' }
      },
      {
        path: 'detail/:id',
        component: () => import('@/views/tms/waybill/info'),
        name: 'waybillEdit',
        meta: { title: '运单信息查看', activeMenu: '/tms/waybill' }
      },
    ]
  },
  {
    path: '/wms/inventoryPlan',
    component: Layout,
    hidden: true,
    permissions: ['wms:inventoryPlan:add'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/wms/inventoryPlan/form'),
        name: 'inventoryPlanAdd',
        meta: { title: '盘点计划信息-新增', activeMenu: '/wms/wmsinventoryplan' }
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/wms/inventoryPlan/form'),
        name: 'inventoryPlanEdit',
        meta: { title: '盘点计划信息-编辑', activeMenu: '/wms/wmsinventoryplan' }
      }
    ]
  },
  {
    path: '/oms/stagingInfo',
    component: Layout,
    hidden: true,
    permissions: ['oms:staging:add','oms:staging:edit'],
    children: [
      {
        path: 'add',
        component: () => import('@/views/oms/staging/edit'),
        name: 'stagingAdd',
        meta: { title: '移交登记信息-新增', activeMenu: '/oms/staging' }
      },
      {
        path: 'edit/:pno',
        component: () => import('@/views/oms/staging/edit'),
        name: 'stagingEdit',
        meta: { title: '移交登记信息-编辑', activeMenu: '/oms/staging' }
      },
      {
        path: 'detail/:id',
        component: () => import('@/views/oms/staging/detail'),
        name: 'stagingDetail',
        meta: { title: '移交登记信息-查看', activeMenu: '/oms/staging' }
      }
    ]
  },
  {
    path: '/system/sysModel',
    component: Layout,
    hidden: true,
    permissions: ['buss:report:list'],
    children: [
      {
        path: 'detail/:objId',
        component: () => import('@/views/system/sysModel/detail'),
        name: 'formDetail',
        meta: { title: '详情', activeMenu: '/system/workflow' }
      },
      {
        path: 'detailLog/:objId',
        component: () => import('@/views/system/sysModel/detailLog'),
        name: 'logFormDetail',
        meta: { title: '详情', activeMenu: '/workflow/sysWorklog' }
      }
    ]
  },

  {
    path: '/system/notices',
    component: Layout,
    hidden: true,
    permissions: ['system:notice:list'],
    children: [
      {
        path: 'users/:objId',
        component: () => import('@/views/system/noticeUser/index'),
        name: 'noticeUsers',
        meta: { title: '通知公告详情', activeMenu: '/system/notice' }
      }
    ]
  },

  {
    path: '/oms/boxlog',
    component: Layout,
    hidden: true,
    permissions: ['oms:boxDept:list'],
    children: [
      {
        path: 'list',
        component: () => import('@/views/oms/boxDept/index'),
        name: 'boxlog',
        meta: { title: '领用记录', activeMenu: 'oms/baseData/box' }
      }
    ]
  },
  {
    path: '/tms/drivers',
    component: Layout,
    hidden: true,
    permissions: ['tms:driver:list'],
    children: [
      {
        path: 'detail/:id',
        component: () => import('@/views/tms/driver/info'),
        name: 'driverInfo',
        meta: { title: '驾驶员档案', activeMenu: '/tms/driver' }
      }
    ]
  },

]

export default new Router({
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
